package com.alibaba.otter.node.etl.load.loader.mq.rabbit.namespace;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

public abstract class AbstractSettingResolver<T extends Namespace> implements NamespaceResolver<T> {

    protected String name;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getPrefix() {
//        if (StringUtils.isNotBlank(getName())) {
//            return getName() + "." + getType() + ".";
//        }
//        return getType() + ".";
        return "";
    }

    protected <S> S resolveSetting(Map<String, Object> properties, Class<S> settingClass) {
        JSONObject jsonObject = new JSONObject();
        properties.entrySet().forEach(entry ->
                jsonObject.put(entry.getKey(), entry.getValue())
        );
        return jsonObject.toJavaObject(settingClass);
    }
}
